<?php
/* 
 * ebiz front
 * 
 * FeatureView
 * 
 * @author allen
 * 
 */

require_once '../app/util/TemplateReplaceUtil.php';
require_once '../app/util/TagUtil.php';
require_once '../app/views/HeaderView.php';
require_once '../app/views/FooterView.php';

class FeatureView {
	
	protected $commonHeader = null;
	protected $commonFooter = null;
	protected $featureService = null;
	
	public function __construct(){
		$this->commonHeader = new HeaderView();
		$this->commonFooter = new FooterView();
		$this->featureService = new FeatureService();
	}

	public function getViewByUrl($result){
        $config = $GLOBALS["config"]; 
        $header = new HeaderView();
        $footer = new FooterView();
        $scpPath = "layout/feature.scp";     //replace .scl file layout
        $datascp = TemplateReplaceUtil::getTemplate($scpPath);
        $arr = array();
        $arr =  TemplateReplaceUtil::getXmlParam($datascp);     //return the param in the array
        //set the template of header and footer page  
        $headerName = isset($arr["header_content"]["name"]) ? $arr["header_content"]["name"] : "header";
        $headerTemplateName = $headerName.".sch";
        $headerAttributeName = $headerName.".scp";
        $headerView = $header->getCommonHeaderView($headerTemplateName, $headerAttributeName); 
        $footerName = isset($arr["footer_content"]["name"]) ? $arr["footer_content"]["name"] : "footer";
        $footerTemplateName = $footerName.".sct";
        $footerAttributeName = $footerName.".scp";
        $footerView = $footer->getCommonFooterView($footerTemplateName, $footerAttributeName); 
//        get the content from DB, include JS,CSS,content
        $content = $result;
        $htmlFromDB = $content[0]["html"];
        $cssFromDB = $content[0]["css"];
        $javascriptFromDB = $content[0]["javascript"];
        $sclPath = "layout/feature.scl"; 	//replace .scl file layout
		$datascl = TemplateReplaceUtil::getTemplate($sclPath);
		$datascl = TemplateReplaceUtil::replaceTemplate("<javascript_file/>", "", $datascl);
		$datascl = TemplateReplaceUtil::replaceTemplate("<css_file/>", "", $datascl);
		$datascl = TemplateReplaceUtil::replaceTemplate("<header_content/>", $headerView, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<main_content/>", $htmlFromDB, $datascl);
        $datascl = TemplateReplaceUtil::replaceTemplate("<footer_content/>", $footerView, $datascl);
        $menu = "";
        $html = "";
        $html .= "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
        $html .= "<html xmlns='http://www.w3.org/1999/xhtml'>";
        $html .= "<head>";
        $html .= "<meta content='text/html; charset=utf-8' http-equiv='Content-Type' />";
        $html .= "<title></title>";
        $html .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/n/javascript/lib/jquery.js'></script>";
        $html .= "<script type='text/javascript' language='javascript' src='//".ConfigConstants::$iConstants.".".DOMAIN."/n/javascript/frontend.js'></script>";
        $html .= "<link href='//".ConfigConstants::$iConstants.".".DOMAIN."/t/".$config['template_name']."/css/style.css' rel='stylesheet' type='text/css' />";
        $html .= $header->getHeadInfo();
        $html .= $javascriptFromDB;
        $html .= $cssFromDB;
        $html .= $menu;
        $html .= "</head>";
        $html .= "<body>";
        $html .= $datascl;
        $html .= CommonUtil::endTimeFunction();
        $html .= CommonUtil::getDBConnectionNumber(); 
        $html .= "</body>";
        $html .= "</html>";
        return $html;
	}
	
}


